import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class DatabaseInitializer {
    public static void main(String[] args) {
        String url = "jdbc:mysql://127.0.0.1:3306/wvp?useUnicode=true&characterEncoding=UTF8&serverTimezone=PRC&useSSL=false&allowMultiQueries=true&allowPublicKeyRetrieval=true";
        String username = "root";
        String password = "12345678";
        
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection(url, username, password);
            Statement stmt = conn.createStatement();
            
            System.out.println("连接数据库成功！");
            
            // 创建 wvp_record_plan 表
            String createRecordPlanTable = "CREATE TABLE IF NOT EXISTS wvp_record_plan (" +
                "id INT AUTO_INCREMENT PRIMARY KEY," +
                "snap TINYINT(1) DEFAULT 0," +
                "name VARCHAR(255) NOT NULL," +
                "create_time VARCHAR(50)," +
                "update_time VARCHAR(50)" +
                ")";
            
            stmt.executeUpdate(createRecordPlanTable);
            System.out.println("创建 wvp_record_plan 表成功！");
            
            // 创建 wvp_record_plan_item 表
            String createRecordPlanItemTable = "CREATE TABLE IF NOT EXISTS wvp_record_plan_item (" +
                "id INT AUTO_INCREMENT PRIMARY KEY," +
                "start INT," +
                "stop INT," +
                "week_day INT," +
                "plan_id INT," +
                "create_time VARCHAR(50)," +
                "update_time VARCHAR(50)" +
                ")";
            
            stmt.executeUpdate(createRecordPlanItemTable);
            System.out.println("创建 wvp_record_plan_item 表成功！");
            
            // 检查表是否存在
            stmt.executeQuery("SHOW TABLES LIKE 'wvp_record_plan%'");
            System.out.println("数据库表检查完成！");
            
            stmt.close();
            conn.close();
            System.out.println("数据库初始化完成！");
            
        } catch (Exception e) {
            System.err.println("数据库初始化失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
}
